/*
 * Ext GWT - Ext for GWT
 * Copyright(c) 2007-2009, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */
package com.hy.mydesktop.client.mvc.logindialog;


import java.util.Map;

import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.event.EventType;
import com.extjs.gxt.ui.client.mvc.AppEvent;
import com.extjs.gxt.ui.client.mvc.Controller;
import com.extjs.gxt.ui.client.mvc.Dispatcher;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.hy.mydesktop.client.component.event.AppEvents;
import com.hy.mydesktop.client.mvc.base.BaseController;
import com.hy.mydesktop.client.mvc.base.Presenter;
import com.hy.mydesktop.client.mvc.constant.MvcConstants;
import com.hy.mydesktop.shared.util.log.MyLoggerUtil;


/**
 * 
 * 
 * <ul>
 * <li>开发作者：花宏宇</li>
 * <li>设计日期：2011-9-13；时间：上午10:07:41</li>
 * <li>类型名称：LoginController</li>
 * <li>设计目的：用户登录控制器，默认注册：<br>
 * AppEvents.DESKTOP_USER_LOGIN
 * 和AppEvents.DESKTOP_UER_LOGIN_VALIDATE事件
 *  </li>
 * </ul>
 * <ul>
 * <b>修订编号：</b>
 * <li>修订日期：</li>
 * <li>修订作者：</li>
 * <li>修订原因：</li>
 * <li>修订内容：</li>
 * </ul>
 */
public class LoginController extends BaseController {

  private LoginPresenter loginPresenter;


  public LoginController() {
    super();
    registerEventTypes(AppEvents.DESKTOP_USER_LOGIN);
    registerEventTypes(AppEvents.DESKTOP_UER_LOGIN_VALIDATE);
//    registerEventTypes(AppEvents.Error);
//	MyLoggerUtil.printDebug(this.getClass(), "创建 "+this.getClass().getName());
//	MyLoggerUtil.printControllerDebugForInit(getClass());
    super.printControllerForInit(getClass());

  }

  public void handleEvent(AppEvent event) {
    EventType type = event.getType();
    //TODO 应该补充控制器的验证功能
     if (type == AppEvents.DESKTOP_USER_LOGIN) {
		 MyLoggerUtil.printControllerDebugForEvent(getClass(), event.getData(MvcConstants.EVENT_NAME).toString());
    	 forwardToView(loginPresenter, event);
    } 
     
     if (type == AppEvents.DESKTOP_UER_LOGIN_VALIDATE) {
    	 MyLoggerUtil.printControllerDebugForEvent(getClass(), event.getData(MvcConstants.EVENT_NAME).toString());
    	 forwardToView(loginPresenter, event);
    } 
     /*EventStructureMetaModel eventStructureMetaModel =(EventStructureMetaModel)((Map<String, Object>)event.getData()).get("eventstructuremetamodel");
		
		//0002
		if (AppEvents.DESKTOP_INIT_FOR_LOGGED_IN_USER==event.getType()) {
			//通过EventStructureMetaModel识别，是否应该处理该事件
			if (eventStructureMetaModel==null||eventStructureMetaModel.getControllerId()==null||eventStructureMetaModel.getControllerId()==this.getId()) {
				forwardToView(shortcutView, event);
				 this.forwardToChild(event);
			}
			 
		}; */
		
		
		/**
		 * 将事件转发给子节点，及子控制器
		 * 注:当前控制器，含有子节点的时候，必不可少
		 */
		
  }

  public void initialize() {
	    loginPresenter = new LoginPresenter(this,new LoginView());

  }

  protected void onError(AppEvent ae) {
    System.out.println("error: " + ae.<Object>getData());
  }
  
 
  

}
